import Vue from "vue";
import VueRouter from "vue-router";
import login from "../views/login/login.vue";
import index from "../views/index/index.vue";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "login",
    component: login,
  },
  {
    path: "/index",
    name: "index",
    component: index,
  },
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

/* 
  根据url地址以及当前是否登录进入相关页面，防止地址栏输入地址进入页面
*/
router.beforeEach((to, from, next) => {
  console.log("进入路由守卫：", to, from);
  next();
  //判断当前路由是否需要权限控制
  //   if () {
  //     //权限控制的具体规则
  //     next(); //旅行
  //   } else {
  //     alert("暂无权限查看");
  //   }
  // } else {
  //   next();
});

export default router;
